let scoreType = -1
let name = location.search;
let sum = decodeURI(name.slice(name.indexOf("=") + 1))
let tile

const items = document.querySelector('.items')

const res = async () => {
  const data = await axios.get(`/comment/list&scoreType=${scoreType}&goodsId=${sum}&page=1`)
  // console.log(data)
  const list = data.data.data.list.data
  console.log(list)

  const i = `<i class="iconfont icon-shoucangwujiaoxing"></i>`
  if (list.length === 0) {
    items.innerHTML = `
      <div class="notHave">
        <img src="./imgs/empty.png" alt="" />
        <p>亲，暂无相关商品评价</p>
      </div>
    `
  } else {
    
    items.innerHTML = list.map(item => {
      return `
      <div class="comment-items">
        <div class="top">
          <div class="img" style = "background-image:url(${item.user.avatar_url===null ? 'http://cba.itlike.com/public/mweb/static/default-avatar.png' : item.user.avatar_url});">
          </div>
          <div class="phone">${item.user.nick_name}</div>
          <div class="icon">${item.score===10?'<i class="iconfont icon-shoucangwujiaoxing"></i><i class="iconfont icon-shoucangwujiaoxing"></i><i class="iconfont icon-shoucangwujiaoxing"></i><i class="iconfont icon-shoucangwujiaoxing"></i><i class="iconfont icon-shoucangwujiaoxing"></i>' :item.score===20?'<i class="iconfont icon-shoucangwujiaoxing"></i><i class="iconfont icon-shoucangwujiaoxing"></i><i class="iconfont icon-shoucangwujiaoxing"></i>' :i}</div>
          <div class="time">${item.create_time}</div>
        </div>
        <div class="content">${item.content}</div>
        <div class="bottom">${item.images.length === 0 ? '' : item.images.map(e => {return `<img src=${e.image_url} alt="" />`
        }).join('')}</div>
      </div>
      `
    }).join('')
  }
}
res()
const som = axios.get(`/comment/total&goodsId=${sum}`).then(res => {
  tile = res.data.data.total
  document.querySelector("#all").innerHTML = `全部(${tile.all})`
  document.querySelector("#praise").innerHTML = `好评(${tile.praise})`
  document.querySelector("#review").innerHTML = `中评(${tile.review})`
  document.querySelector("#negative").innerHTML = `差评(${tile.negative})`
})
document.querySelector('.tab-head ul').addEventListener('click', function (e) {
  if (e.target.tagName === 'LI') {
    document.querySelector('.tab-head .current').classList.remove('current')
    e.target.classList.add('current')
    if (e.target.innerHTML === `全部(${tile.all})`) {
      scoreType = -1
      res()
    }else if (e.target.innerHTML === `好评(${tile.praise})`) {
      scoreType = 10
      res()
    }else if (e.target.innerHTML === `中评(${tile.review})`) {
      scoreType = 20
      res()
    } else {
      scoreType = 30
      res()
    }
  }
})